18C - Stripe - CodeForces Solution


data structures implementation *1200

Please click on ads to support us..

Python Code:

n = int(input())
li = list(map(int, input().split()))
pref_li = list()
sum_li = 0
cnt = 0
for i in range(n):
    sum_li += li[i]
    pref_li.append(sum_li)
for i in range(n-1):
    if pref_li[n-1]%2 == 0 and pref_li[n-1]/2 == pref_li[i]:
        cnt += 1
print(cnt)

C++ Code:

#include <bits/stdc++.h>

#define endl "\n"
#define loopUP(i, s, e, increament) for(int i = (s); i < (e); i+=increament)
#define loopDOWN(i, s, e, decreament) for(int i = (s); i >= (e); i-=decreament)
#define ll long long

using namespace std;

/*
  A-Z 65-90 to convert to small +32
  a-z 97-122 to convert to capital -32
  0-9 48-57
*/
ll m = 1e9+7;

void solve(){
  int n;
  cin>>n;

  int arr[n+1];
  arr[0]=0;

  loopUP(i, 1, n+1, 1)
    cin>>arr[i];
  
  loopUP(i, 1, n+1, 1)
    arr[i] += arr[i-1];

  int ans=0;
  loopUP(i, 2, n+1, 1){
    if(arr[i-1] == arr[n]-arr[i-1])
    ans++;
  }
  cout<<ans<<endl;
}

int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  // freopen("input", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int t=1;

  //cin>>t;
  //loopUP(i, 1, t+1, 1) solve(i);
  while(t--) {
    solve();
  }
  return 0;
}


Comments

Submit
0 Comments
More Questions

1136A - Nastya Is Reading a Book
1353B - Two Arrays And Swaps
1490E - Accidental Victory
1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)
1151B - Dima and a Bad XOR
1435B - A New Technique
1633A - Div 7
268A - Games
1062B - Math
1294C - Product of Three Numbers
749A - Bachgold Problem
1486B - Eastern Exhibition
1363A - Odd Selection
131B - Opposites Attract
490C - Hacking Cypher
158B - Taxi
41C - Email address
1373D - Maximum Sum on Even Positions
1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion